package member.order.util;

import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import member.order.model.OrderModel;

import java.util.Random;

public class OrderNoUtil {
    /**
     * 生成新随机单号
     */
    public static <T extends OrderModel> String newOrderNo(Class<T> clazz,String businessOid,String prefix) throws Exception {
        String key = prefix+"-"+(1000 + new Random().nextInt(9000));
        T m=ModelQueryList.getModel(clazz,new String[]{"oid"},
            QueryCondition.and(
                QueryCondition.eq("business.oid",businessOid),
                QueryCondition.eq("orderNo", key)
            )
        );
        if(null==m) return key;
        else return newOrderNo(clazz,businessOid,prefix);
    }
}
